package top.zhangjianyong.utils;

import java.io.File;
import java.util.Stack;
import java.util.function.Consumer;
import java.util.stream.Stream;

/**
 * @author ： zhangjianyong
 * @date ： 2022/6/25 3:30 PM
 */
public class FileUtil {


    public static void doIteration(Stack<File> stack, Consumer<File> consumer) {
        if (!stack.isEmpty()) {
            File file = stack.pop();
            File[] files = file.listFiles();
            Stream.of(files).parallel().forEach(f -> {
                if (f.isDirectory()) {
                    stack.push(f);
                } else if (f.isFile()) {
                    consumer.accept(f);
                }
            });
            doIteration(stack, consumer);
        }
    }

}
